﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD;
using Xunit;

namespace DokiDokiTest {
    public class TestCamera {
        [Fact]
        public void Test_New1 () {
            var cam = new Camera ();

            Assert.Equal (ProjectionType.Parallel, cam.Type);
            Assert.Equal (1, cam.Fovy);
            Assert.Equal (1, cam.AspectRatio);
            Assert.Equal (0.1f, cam.NearClip);
            Assert.Equal (100, cam.FarClip);
            Assert.Equal (Matrix4x4.Identity, cam.ProjectionMatrix);
        }

        [Fact]
        public void Test_SetParallel(){
            var cam = new Camera ();
            cam.SetParallel (100, 2, 1, 100);

            var expected = new Matrix4x4 (0.01f, 0, 0, 0,
                                           0, 0.02f, 0, 0,
                                           0, 0, -0.02020202f, -1.020202f,
                                           0, 0, 0, 1);

            Assert.Equal (ProjectionType.Parallel, cam.Type);
            Assert.Equal (100, cam.Fovy);
            Assert.Equal (2, cam.AspectRatio);
            Assert.Equal (1, cam.NearClip);
            Assert.Equal (100, cam.FarClip);
            Assert.Equal (expected, cam.ProjectionMatrix);
        }

        [Fact]
        public void Test_SetPerspective () {
            var cam = new Camera ();
            cam.SetPerspective (45, 1.33f, 0.1f, 100);

            var expected = new Matrix4x4 (1.815198f, 0, 0, 0,
                                           0, 2.414213f, 0, 0,
                                           0, 0, -1.002002f, -0.2002002f,
                                           0, 0, -1, 0);

            Assert.Equal (ProjectionType.Perspective, cam.Type);
            Assert.Equal (45, cam.Fovy);
            Assert.Equal (1.33f, cam.AspectRatio);
            Assert.Equal (0.1f, cam.NearClip);
            Assert.Equal (100, cam.FarClip);
            Assert.Equal (expected, cam.ProjectionMatrix);
        }

        [Fact(Skip="未実装")]
        public void Test_SetScreen () {
            var cam = new Camera ();
            cam.SetScreen (0,0,640, 480);

            var expected = new Matrix4x4 (0, 0, 0, 0,
                                           0, 0, 0, 0,
                                           0, 0, 0, 0,
                                           0, 0, 0, 0);

            Assert.Equal (ProjectionType.Parallel, cam.Type);
            Assert.Equal (100, cam.Fovy);
            Assert.Equal (2, cam.AspectRatio);
            Assert.Equal (1, cam.NearClip);
            Assert.Equal (100, cam.FarClip);
            Assert.Equal (expected, cam.ProjectionMatrix);
        }

        [Fact]
        public void Test_SetGeneric () {
            var cam = new Camera ();
            var expected = new Matrix4x4 (1,2,3,4,
                                          5,6,7,8,
                                          9,10,11,12,
                                          13,14,15,16);
            cam.SetGeneric (expected);

            Assert.Equal (ProjectionType.Generic, cam.Type);
            Assert.Equal (expected, cam.ProjectionMatrix);
        }
    }
}
